package com.demo.take.util;

import lombok.SneakyThrows;
import org.springframework.util.StopWatch;

import java.util.concurrent.TimeUnit;

public class StopWatchTest {

    public static void main(String[] args) {
//        test();
        test1();
    }

    @SneakyThrows
    public static void test() {
        long startTime = System.currentTimeMillis();
        TimeUnit.SECONDS.sleep(1);
        long endTime = System.currentTimeMillis();
        System.out.println("testUtil执行时间:" + (endTime - startTime));
    }


    @SneakyThrows
    public static void test1() {
        StopWatch stopWatch = new StopWatch("多任务");
        stopWatch.start("任务一");
        TimeUnit.MILLISECONDS.sleep(100);
        stopWatch.stop();

        stopWatch.start("任务二");
        TimeUnit.MILLISECONDS.sleep(200);
        stopWatch.stop();

        System.out.println(stopWatch.prettyPrint());
        System.out.println("多任务总耗时：" + stopWatch.getTotalTimeMillis() + "毫秒");
    }

}
